home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime vr / vrscript / feature files / vrsprites.c < prev    next >
Encoding:
Text File  |  2000-09-28  |  6.8 KB  |  259 lines

  1. //////////
  2. //
  3. //    File:        VRSprites.c
  4. //
  5. //    Contains:    Support for QuickTime sprite tracks in VR nodes.
  6. //
  7. //    Written by:    Tim Monroe
  8. //
  9. //    Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //    Change History (most recent first):
  12. //
  13. //       <2>         06/24/98    rtm        added VRSprites_SetLocation; general clean-up
  14. //       <1>         06/19/98    rtm        first file, based on code in QTSprites.c; added VRSprites_Set*;
  15. //                                    moved to new routine names (e.g. SpriteMediaSetSpriteProperty)
  16. //       
  17. //    This code supports displaying and hit-testing QuickTime sprite tracks in QTVR movies.
  18. //
  19. //////////
  20.  
  21. // header files
  22. #include "VRSprites.h"
  23.  
  24.  
  25. //////////
  26. //
  27. // VRSprites_InitWindowData
  28. // Initialize window-specific data for sprites.
  29. //
  30. //////////
  31.  
  32. void VRSprites_InitWindowData (WindowObject theWindowObject)
  33. {
  34.     ApplicationDataHdl    myAppData = NULL;
  35.     MediaHandler        myHandler = NULL;
  36.     Track                myTrack = NULL;
  37.     
  38.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  39.     if (myAppData != NULL) {
  40.  
  41.         // look for any sprite tracks in the VR movie file
  42.         myTrack = GetMovieIndTrackType((**theWindowObject).fMovie, 1, SpriteMediaType, movieTrackMediaType | movieTrackEnabledOnly);
  43.         if (myTrack != NULL)
  44.             myHandler = GetMediaHandler(GetTrackMedia(myTrack));
  45.     
  46.         // remember the sprite media handler
  47.         (**myAppData).fMovieHasSprites = (myTrack != NULL);
  48.         (**myAppData).fSpriteHandler = myHandler;
  49.     }
  50. }
  51.  
  52.  
  53. //////////
  54. //
  55. // VRSprites_DumpWindowData
  56. // Get rid of any window-specific data for sprites.
  57. //
  58. //////////
  59.  
  60. void VRSprites_DumpWindowData (WindowObject theWindowObject)
  61. {
  62. #pragma unused(theWindowObject)
  63.  
  64. }
  65.  
  66.  
  67. //////////
  68. //
  69. // VRSprites_SetVisibleState
  70. // Set the visibility state (on or off) of a sprite.
  71. //
  72. //////////
  73.  
  74. void VRSprites_SetVisibleState (WindowObject theWindowObject, QTAtomID theSpriteID, Boolean theState, UInt32 theOptions)
  75. {
  76. #pragma unused(theOptions)
  77.  
  78.     ApplicationDataHdl        myAppData = NULL;
  79.     MediaHandler            myHandler = NULL;
  80.     Boolean                    isVisible;
  81.  
  82.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  83.     if (myAppData == NULL)
  84.         return;
  85.  
  86.     myHandler = (**myAppData).fSpriteHandler;
  87.     if (myHandler == NULL)
  88.         return;
  89.  
  90.     if (theState == kVRState_Toggle) {
  91.         SpriteMediaGetSpriteProperty(myHandler, theSpriteID, kSpritePropertyVisible, (void *)&isVisible);
  92.         SpriteMediaSetSpriteProperty(myHandler, theSpriteID, kSpritePropertyVisible, (void *)!isVisible);
  93.     } else {
  94.         SpriteMediaSetSpriteProperty(myHandler, theSpriteID, kSpritePropertyVisible, (void *)(theState == kVRState_Show));
  95.     }
  96. }
  97.  
  98.  
  99. //////////
  100. //
  101. // VRSprites_SetLayer
  102. // Set the layer of a sprite.
  103. //
  104. //////////
  105.  
  106. void VRSprites_SetLayer (WindowObject theWindowObject, QTAtomID theSpriteID, short theLayer, UInt32 theOptions)
  107. {
  108. #pragma unused(theOptions)
  109.  
  110.     ApplicationDataHdl        myAppData = NULL;
  111.     MediaHandler            myHandler = NULL;
  112.  
  113.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  114.     if (myAppData == NULL)
  115.         return;
  116.  
  117.     myHandler = (**myAppData).fSpriteHandler;
  118.     if (myHandler == NULL)
  119.         return;
  120.         
  121.     SpriteMediaSetSpriteProperty(myHandler, theSpriteID, kSpritePropertyLayer, (void *)theLayer);
  122. }
  123.  
  124.  
  125. //////////
  126. //
  127. // VRSprites_SetGraphicsMode
  128. // Set the graphics mode of a sprite.
  129. //
  130. //////////
  131.  
  132. void VRSprites_SetGraphicsMode (WindowObject theWindowObject, QTAtomID theSpriteID, long theMode, UInt32 theOptions)
  133. {
  134. #pragma unused(theOptions)
  135.  
  136.     ApplicationDataHdl                    myAppData = NULL;
  137.     MediaHandler                        myHandler = NULL;
  138.     ModifierTrackGraphicsModeRecord        myRec;
  139.  
  140.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  141.     if (myAppData == NULL)
  142.         return;
  143.  
  144.     myHandler = (**myAppData).fSpriteHandler;
  145.     if (myHandler == NULL)
  146.         return;
  147.         
  148.     SpriteMediaGetSpriteProperty(myHandler, theSpriteID, kSpritePropertyGraphicsMode, &myRec);
  149.     myRec.graphicsMode = theMode;
  150.     SpriteMediaSetSpriteProperty(myHandler, theSpriteID, kSpritePropertyGraphicsMode, &myRec);
  151. }
  152.  
  153.  
  154. //////////
  155. //
  156. // VRSprites_SetImageIndex
  157. // Set the image index of a sprite.
  158. //
  159. // Remember that the image index is the index in the entire set of sprite images in a sprite track,
  160. // NOT (necessarily) the index of the images attached to the sprite with the specified ID. 
  161. //
  162. //////////
  163.  
  164. void VRSprites_SetImageIndex (WindowObject theWindowObject, QTAtomID theSpriteID, short theIndex, UInt32 theOptions)
  165. {
  166. #pragma unused(theOptions)
  167.  
  168.     ApplicationDataHdl        myAppData = NULL;
  169.     MediaHandler            myHandler = NULL;
  170.  
  171.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  172.     if (myAppData == NULL)
  173.         return;
  174.  
  175.     myHandler = (**myAppData).fSpriteHandler;
  176.     if (myHandler == NULL)
  177.         return;
  178.         
  179.     SpriteMediaSetSpriteProperty(myHandler, theSpriteID, kSpritePropertyImageIndex, (void *)theIndex);
  180. }
  181.  
  182.  
  183. //////////
  184. //
  185. // VRSprites_SetMatrix
  186. // Set the matrix of a sprite.
  187. //
  188. //////////
  189.  
  190. void VRSprites_SetMatrix (WindowObject theWindowObject, QTAtomID theSpriteID, MatrixRecord *theMatrix, UInt32 theOptions)
  191. {
  192. #pragma unused(theOptions)
  193.  
  194.     ApplicationDataHdl        myAppData = NULL;
  195.     MediaHandler            myHandler = NULL;
  196.  
  197.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  198.     if (myAppData == NULL)
  199.         return;
  200.  
  201.     myHandler = (**myAppData).fSpriteHandler;
  202.     if (myHandler == NULL)
  203.         return;
  204.         
  205.     SpriteMediaSetSpriteProperty(myHandler, theSpriteID, kSpritePropertyMatrix, theMatrix);
  206. }
  207.  
  208.  
  209. //////////
  210. //
  211. // VRSprites_SetLocation
  212. // Set the location of a sprite.
  213. //
  214. // The thePoint parameter specifies either the desired absolute position or the desired relative offset
  215. // from the current position, depending on whether theOptions is kVRValue_Absolute or kVRValue_Relative.
  216. // Values for the fields in thePoint are in pixels.
  217. //
  218. //////////
  219.  
  220. void VRSprites_SetLocation (WindowObject theWindowObject, QTAtomID theSpriteID, Point *thePoint, UInt32 theOptions)
  221. {
  222.     ApplicationDataHdl        myAppData = NULL;
  223.     MediaHandler            myHandler = NULL;
  224.  
  225.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  226.     if (myAppData == NULL)
  227.         return;
  228.  
  229.     myHandler = (**myAppData).fSpriteHandler;
  230.     if (myHandler != NULL) {
  231.         MatrixRecord        myMatrix;
  232.         long                myNewH = (long)(thePoint->h);
  233.         long                myNewV = (long)(thePoint->v);
  234.         
  235.         // get the current matrix for the specified sprite
  236.         SpriteMediaGetSpriteProperty(myHandler, theSpriteID, kSpritePropertyMatrix, &myMatrix);
  237.     
  238.         // theOptions determines whether the new location is absolute or relative to the current location
  239.         if (theOptions == kVRValue_Absolute) {
  240.             myMatrix.matrix[2][0] = Long2Fix(myNewH);
  241.             myMatrix.matrix[2][1] = Long2Fix(myNewV);
  242.         } else {
  243.             long            myCurrH = Fix2Long(myMatrix.matrix[2][0]);
  244.             long            myCurrV = Fix2Long(myMatrix.matrix[2][1]);
  245.             
  246.             myCurrH += myNewH;
  247.             myCurrV += myNewV;
  248.         
  249.             myMatrix.matrix[2][0] = Long2Fix(myCurrH);
  250.             myMatrix.matrix[2][1] = Long2Fix(myCurrV);
  251.         }
  252.         
  253.         // set the new matrix for the specified sprite    
  254.         SpriteMediaSetSpriteProperty(myHandler, theSpriteID, kSpritePropertyMatrix, &myMatrix);
  255.     }
  256. }
  257.  
  258.  
  259.